package cn.lingyangwl.agile.auth.constants;

import cn.lingyangwl.framework.cache.core.key.ICacheKey;
import java.util.concurrent.TimeUnit;

/**
 * @author shenguangyang
 */
public enum CacheKeyEnum implements ICacheKey {

    /**
     * 验证码
     * arg1: uuid
     */
    CAPTCHA("auth:captcha:%s", 60 * 5, TimeUnit.SECONDS),
    /**
     * 检查code是否重复发送
     * arg1: 类型, 登录/注册/找回密码等 {@link SmsEnum}
     * arg2: md5(邮箱/手机号 + 账号),
     */
    CHECK_CODE("auth:check_code:%s:%s", 60, TimeUnit.SECONDS),
    /**
     * 第三方授权 state
     */
    OAUTH_STATE("auth:oauth_state:%s", 360, TimeUnit.SECONDS),
    /**
     * 登录二维码信息
     * arg1: 二维码id
     */
    LOGIN_QR_CODE("auth:login_qr_code:%s", 60, TimeUnit.SECONDS),

    /**
     * 登录时候绑定社交账号
     * arg1: loginId
     * arg2: userId
     * value: 第三方账号的id ==> openId
     */
    LOGIN_BIND_SOCIAL("auth:login_bind_social:%s:%s", -1, null),

    /**
     * 第三方用户信息
     * arg1: 微信小程序手机号code/支付宝小程序code/其他获取用户信息的code
     */
    THIRD_USER_INFO("auth:third_user_info:%s", 5, TimeUnit.MINUTES),

    ;
    private final String key;
    private final int expire;
    private final TimeUnit unit;

    CacheKeyEnum(String key, int expire, TimeUnit unit) {
        this.key = key;
        this.expire = expire;
        this.unit = unit;
    }

    @Override
    public String getKey() {
        return this.key;
    }

    @Override
    public int getExpire() {
        return this.expire;
    }

    @Override
    public TimeUnit getUnit() {
        return this.unit;
    }


}
